package com.study.leetcode;

public class Solution_713 {

    public static int numSubarrayProductLessThanK(int[] nums, int k) {
        if (k <= 1) {
            return 0;
        }
        int ans = 0;
        int prod = 1;
        int left = 0;
        for (int right = 0; right < nums.length; right++) {
            prod *= nums[right];
            while (prod >= k) {
                //缩小左边的边界直到让乘积小于等于 k
                prod /= nums[left];
                left += 1;
            }
            //记录总的答案数量
            ans = ans + right - left + 1;
        }
        return ans;
    }
}
